package com.coollang.smartbra.base;

import android.annotation.SuppressLint;

import com.coollang.smartbra.fragment.EnFragment;
import com.coollang.smartbra.fragment.FirstFragment;
import com.coollang.smartbra.fragment.PersonalFragment;
import com.coollang.smartbra.fragment.SportFragment;

import java.util.HashMap;

@SuppressLint("UseSparseArrays")
public class FragmentFactory {
    // 首页
    public static final int TAB_FIRST = 0;
    // 运动
    public static final int TAB_SPORT = 1;
    // 环境
    public static final int TAB_EN = 2;
    // 个人
    public static final int TAB_PERSONAL = 3;

    // 缓存所有的fragment对象
    public static HashMap<Integer, BaseFragment> mFragmentMap = new HashMap<Integer, BaseFragment>();
    private static BaseFragment mBaseFragment;

    public static BaseFragment createFragment(int position) {
        mBaseFragment = mFragmentMap.get(position);
        if (mBaseFragment == null) {
            switch (position) {
                case TAB_FIRST:
                    mBaseFragment = new FirstFragment();
                    break;
                case TAB_SPORT:
                    mBaseFragment = new SportFragment();
                    break;
                case TAB_EN:
                    mBaseFragment = new EnFragment();
                    break;
                case TAB_PERSONAL:
                    mBaseFragment = new PersonalFragment();
                    break;
            }
            mFragmentMap.put(position, mBaseFragment);
        }
        return mBaseFragment;
    }
}
